package cn.wxq.daily.empdailymgforserve.controller;

import cn.wxq.daily.empdailymgforserve.domain.Administrative;
import cn.wxq.daily.empdailymgforserve.model.Result;
import cn.wxq.daily.empdailymgforserve.model.StatusCode;
import cn.wxq.daily.empdailymgforserve.service.AdministrativeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@CrossOrigin //跨越处理
@RestController
@RequestMapping("/administrative")
@Api(value = "AdministrativeController|行政管理控制器")
public class AdministrativeController {
    @Autowired
    AdministrativeService administrativeService;

    /**
     * 条件查询
     *
     * @param administrative
     * @return
     */
    @RequestMapping(value = "/findByPage", method = RequestMethod.POST)
    @ApiOperation(value = "按条件查询")
    public Result findByPage(Administrative administrative) {
        List<Administrative> res = administrativeService.findByPage(administrative);
        if (res != null) {
            return new Result(true, StatusCode.OK, "获取成功", res);
        } else {
            return new Result(false, StatusCode.ERROR, "返回数据异常");
        }
    }

    /**
     * 物品领用新增
     *
     * @param administrative
     * @return
     */
    @RequestMapping(value = "/insertGoods", method = RequestMethod.POST)
    @ApiOperation(value = "物品领用新增")
    public Result insertGoods(Administrative administrative) {
        int row = administrativeService.insertGoods(administrative);
        if (row > 0) {
            return new Result(true, StatusCode.OK, "新增成功");
        } else {
            return new Result(false, StatusCode.ERROR, "失败");
        }
    }

    /**
     * 用车和用章新增
     *
     * @param administrative
     * @return
     */
    @RequestMapping(value = "/insertCarOrZang", method = RequestMethod.POST)
    @ApiOperation(value = "用车和用章新增")
    public Result insertCarOrZang(Administrative administrative) {
        int row = administrativeService.insertCarOrZang(administrative);
        if (row > 0) {
            return new Result(true, StatusCode.OK, "新增成功");
        } else {
            return new Result(false, StatusCode.ERROR, "失败");
        }
    }

    /**
     * 用户申请修改
     *
     * @param administrative
     * @return
     */
    @RequestMapping(value = "/updateAdministrative", method = RequestMethod.POST)
    @ApiOperation(value = "用户申请修改")
    public Result updateAdministrative(Administrative administrative) {
        int row = administrativeService.updateAdministrative(administrative);
        if (row > 0) {
            return new Result(true, StatusCode.OK, "修改成功");
        } else {
            return new Result(false, StatusCode.ERROR, "失败");
        }
    }

    /**
     * id获取详情
     *
     * @param adtrtId
     * @return
     */
    @RequestMapping(value = "/getInfoById", method = RequestMethod.POST)
    @ApiOperation(value = "id获取详情", notes = "id获取详情")
    public Result getInfoById(Integer adtrtId) {
        Administrative administrative = administrativeService.selectAdministrativeById(adtrtId);
        if (administrative != null) {
            return new Result(true, StatusCode.OK, "获取用户信息成功", administrative);
        } else {
            return new Result(true, StatusCode.ERROR, "获取用户信息失败");
        }

    }

    /**
     * 删除
     *
     * @param adtrtId
     * @return
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    @ApiOperation(value = "删除", notes = "删除")
    public Result deleteById(Integer adtrtId) {
        int row = administrativeService.deleteById(adtrtId);
        return new Result(true, StatusCode.OK, "删除成功");
    }
}
